import Vue from 'vue'
import myHeader from '../../components/Header';
import myFooter from '../../components/Footer';
import centerHeader from '../../components/center-header';
export default {

    components: {
        myHeader,
        myFooter,
        centerHeader
    },
    data() {
        return {
          header: [
            { title: "数据统计", path: "/home/data"},
          ],
          moredata1:'加载更多..',
          showMore:true,
          d_id:'',
          count:'',//倒计时秒
          data1:[],//今日充值
          data2:[],//昨日
          data3:[],//本月
          data4:[],//所有
          data5:'',//详细list
          data6:[],//今日用户
          data7:[],//昨日
          data8:[],//本月
          data9:[],//所有
          data10:[],//用户30天的统计
          data11:[
            {
              text1:'1',
              text2:'2',
              text3:'3',
              text4:'4'
            }
          ],
          data12:[
            {
              text1:'1',
              text2:'2',
              text3:'3',
              text4:'4',
              text5:'5',
              text6:'6',
              text7:'7',
              text8:'8'
            }
          ],
          checkedMsg: 2,
          informationActiveName:'first',
          item:'',
          parameter1: {
            page: 1,
            d_id: ''
          }
        }
    },
    components:{
      centerHeader
    },
    methods: {
      // handleClick(tab, event) {
      //   this[tab.name] && this[tab.name]()
      // },
      //时间戳转换
      timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + "-";
        var M =
          (date.getMonth() + 1 < 10 ?
            "0" + (date.getMonth() + 1) :
            date.getMonth() + 1) + "-";
        var D = date.getDate() + " ";
        var h = date.getHours() + ":";
        var m = date.getMinutes() + ":";
        var s = date.getSeconds();
        return Y + M + D ;
      },
      //倒计时函数
      djs(){
        const TIME_COUNT = 60;
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              clearInterval(this.timer);
              this.timer = null;
              this.nowdata();
              this.nowuser();
            }
          }, 1000)
        }
      },
      //所有数据请求
      first(){
          let that=this;
          that.axios.all([that.getNowdata(),that.getYesdata(),that.getMondata(),that.getAlldata()])
            .then(that.axios.spread(function (a,b,c,d) {
              that.data1.push(a.data.data);
              that.data2.push(b.data.data);
              console.log(b);
              that.data3.push(c.data.data);
              that.data4.push(d.data.data);
            }))
      },
      //今日充值
      nowdata(){
          let that=this;
          that.axios.post('/cp/v1/Order/getindex',{
            d_id:that.d_id
          })
            .then(function (res) {
              // console.log(res);
              if(res.data.code==200){
                that.data1.splice(0,that.data1.length);
                that.data1.push(res.data.data);
                that.djs();
              }
            })
            .catch(function (err) {
              console.log(err);
            })
         },
      //今日充值
      getNowdata(){
          return this.axios.post("/cp/v1/Order/getindex",{
            d_id:this.d_id
          })
         },
      //昨日充值
      getYesdata(){
        return this.axios.post("/cp/v1/Order/getYesterday",{
          d_id:this.d_id
        })
      },
      //当月充值
      getMondata(){
        return this.axios.post("/cp/v1/Order/getMonth",{
          d_id:this.d_id
        })
      },
      //所有充值
      getAlldata(){
        return this.axios.post("/cp/v1/Order/getAccumulative",{
          d_id:this.d_id
        })
      },
      //所有用户统计
      second(){
        let that=this;
        that.getThirty();
        that.axios.all([that.getnowUser(),that.getyesUser(),that.getmonUser(),that.getallUser()])
          .then(that.axios.spread(function (a,b,c,d) {
            that.data6.push(a.data.data);
            that.data7.push(b.data.data);
            // console.log(that.data6);
            that.data8.push(c.data.data);
            that.data9.push(d.data.data);
          }))
      },
      //今日用户统计
      nowuser(){
        let that=this;
        that.axios.post('/cp/v1/Members/getIndex',{
          d_id:that.d_id
        })
          .then(function (res) {
            if(res.data.code==200){
              that.data6.splice(0,that.data1.length);
              that.data6.push(res.data.data);
              // console.log(that.data6);
              that.djs();
            }
          })
          .catch(function (err) {
            console.log(err)
          })
      },
      //今日新增
      getnowUser(){
        return this.axios.post("/cp/v1/Members/getIndex",{
          d_id:this.d_id
        })
      },
      //昨日用户统计
      getyesUser(){
        return this.axios.post("/cp/v1/Members/getYesterday",{
          d_id:this.d_id
        })
      },
      //本月用户统计
      getmonUser(){
        return this.axios.post("/cp/v1/Members/getMonth",{
          d_id:this.d_id
        })
      },
      //所有用户统计
      getallUser(){
        return this.axios.post("/cp/v1/Members/getAccumulative",{
          d_id:this.d_id
        })
      },
      //30天用户统计
      getThirty(){
        let that=this;
        that.axios.post('/cp/v1/Members/getStatistics',{
          d_id:that.d_id
        })
          .then(function (res) {
            that.data10=res.data.data;
          })
          .catch(function (err) {
            console.log(err)
          })
      },
      getList(){
        let that=this;
        that.axios.post('/cp/v1/order/getStatistics',{
          d_id:that.d_id,
          y:10
        })
          .then(function (res) {
            if(res.data.code==200){
              that.data5=res.data.data;
              // console.log(res);
            }else{
              // console.log(res.data.code);
            }
          })
          .catch(function (err) {
            console.log(err);
          })
      },
      //加载更多1
      getMore(){
        let that = this;
        that.$utils.loadmore(that, {
          api: '/cp/v1/order/getStatistics',
          parameter: that.parameter1,
          oldArr: that.data5
        }, function (res) {
          // console.log(res);
          // res.data.data = res.data.data.tot;
            that.showMore=false

        }, function (arr) {
          that.data5 = arr;
        })
      }

},
    created(){
      let d_id=JSON.parse(localStorage.getItem('userInfo')).user_id;
      // console.log(d_id);
      this.d_id=d_id;
      this.parameter1.d_id=d_id;
      this.first();
      this.second();
      this.getList();
      this.djs();
    }

}

